import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/alert/alert.dart';
import 'package:boss/ui/widget/form/base_text_form_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hi_common/hi_common.dart';

Future<int> showBatchPlusSeatModal(BuildContext context) {
  final key = GlobalKey<__BatchPlusSeatModalState>();

  return showAlert<int>(
    context,
    title: '批量添加座位',
    content: _BatchPlusSeatModal(key: key),
    onCancel: (context) {
      Navigator.pop(context);
    },
    onConfirm: (context) {
      int value;

      try {
        value = int.parse(key.currentState.value);
      } catch (e) {}

      Navigator.pop(context, value);
    },
  );
}

class _BatchPlusSeatModal extends StatefulWidget {
  _BatchPlusSeatModal({Key key}) : super(key: key);

  @override
  __BatchPlusSeatModalState createState() => __BatchPlusSeatModalState();
}

class __BatchPlusSeatModalState extends State<_BatchPlusSeatModal> {
  String value;

  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: TextStyleConstant().normal_1_28,
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 30.w),
        child: Row(
          children: [
            Text('创建'),
            Expanded(
              child: BaseTextFormField(
                hintText: '请输入数量',
                textAlign: TextAlign.center,
                inputFormatters: [FilteringTextInputFormatter.allow(RegUtil.integerReg)],
                keyboardType: TextInputType.number,
                onChanged: (value) {
                  this.value = value;
                },
              ),
            ),
            Text('个座位'),
          ],
        ),
      ),
    );
  }
}
